#!/bin/bash

#
# This script counts the number of CPU's present in the machine as
# determined by the information listed in /proc/cpuinfo
#

echo ""
echo "Processor Counter - This script counts the"
echo "number of processors present and available"
echo "to the machine."
echo ""
echo "---"
echo "Usage $0"
echo "---"
echo ""

COWSAY="/usr/games/cowsay"
PROCESSORCOUNT=`cat /proc/cpuinfo | grep processor | wc -l`
FORTUNE="/usr/games/fortune"

if [ $PROCESSORCOUNT -gt 1 ]; then
	# Multiple (more than one) processors.
	RESULT="There are $PROCESSORCOUNT processors present and available to this machine."
else
	# Single processor.
	RESULT="There is $PROCESSORCOUNT processor present and available to this machine."
fi


if [ -x $COWSAY ]; then
	$COWSAY $RESULT
	echo ""
else
	echo $RESULT
fi

echo "---- ---- ---- ---- ---- ---- ---- ----"

if [ -x $FORTUNE ]; then
	echo ""
	$FORTUNE -s
	echo ""
	echo "---- ---- ---- ---- ---- ---- ---- ----"
fi


